package cn.aitrox.ry.service.anno.dao.impl;

import cn.aitrox.ry.common.dao.MapperSqlCallback;
import cn.aitrox.ry.common.dao.impl.BaseDaoImpl;
import cn.aitrox.ry.service.anno.dao.TaskSeriesDao;
import cn.aitrox.ry.service.anno.entity.TaskSeriesEntity;
import cn.aitrox.ry.service.anno.mapper.TaskSeriesMapper;
import cn.aitrox.ry.service.anno.po.task.TaskSeriesCountPo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class TaskSeriesDaoImpl extends BaseDaoImpl<TaskSeriesEntity> implements TaskSeriesDao {

    @Autowired
    private TaskSeriesMapper mapper;

    @Override
    public void batchSave(List<TaskSeriesEntity> list) {
        batchInsert(list, 1000, new MapperSqlCallback<TaskSeriesEntity>() {
            @Override
            public void batchInsert(List<TaskSeriesEntity> objList) {
                mapper.batchInsert(objList);
            }
        });
    }

    @Override
    public void deleteByTaskId(Integer taskId) {
        mapper.deleteByTaskId(taskId);
    }

    @Override
    public List<TaskSeriesCountPo> findTaskSeriesCountByTaskIds(List<Integer> taskIdList) {
        return mapper.findTaskSeriesCountByTaskIds(taskIdList);
    }

    @Override
    public List<TaskSeriesEntity> findByTaskId(Integer taskId) {
        if (null == taskId) {
            return new ArrayList<>();
        }
        TaskSeriesEntity cond = new TaskSeriesEntity();
        cond.setTaskId(taskId);
        return findByCondition(cond, null);
    }

    @Override
    public List<TaskSeriesEntity> findByTaskIdGroupId(Integer taskId, String groupId) {
        if (null == taskId || null == groupId) {
            return new ArrayList<>();
        }
        TaskSeriesEntity cond = new TaskSeriesEntity();
        cond.setTaskId(taskId);
        cond.setGroupId(groupId);
        return findByCondition(cond, null);
    }

    @Override
    public Integer findGroupIdCountByTaskId(Integer taskId) {
        return mapper.findGroupIdCountByTaskId(taskId);
    }

    @Override
    public TaskSeriesEntity findByTaskSeriesUid(Integer taskId, String seriesUid) {
        if (null == taskId || null == seriesUid) {
            return null;
        }
        TaskSeriesEntity cond = new TaskSeriesEntity();
        cond.setTaskId(taskId);
        cond.setSeriesUid(seriesUid);
        return super.findOne(cond);
    }
}
